<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>XXX后台管理</title>
    <script src="js/jquery-3.2.1.js"></script>
    <script src="layui/layui.js"></script>
    <script src="layui/lay/modules/layer.js"></script>
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="layui/css/modules/layer/default/layer.css">
</head>
<body>
<form style="display: flex;justify-content: flex-end;margin-top: 8px" method="post" class="layui-form"
      action="/manager/addRoleToObejectManager">
    <div style="margin: 0;padding: 0" class="layui-form-item">
        <label class="layui-form-label">请选择</label>
        <div class="layui-input-block">
            <select style="padding: 0;margin:0;" required name="r_name" lay-verify="required">
                <#list allRoleList as r>
                <option value="${r.r_name}">${r.r_name}</option>
            </#list>
            </select>
        </div>
    </div>
    <div style=";margin: 0;padding: 0" class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">添加</button>
        </div>
    </div>
</form>
<table style="border: solid red 1px" id="demo" lay-filter="test"></table>
<script>
    layui.use('table', function () {
        var table = layui.table;

        //第一个实例
        table.render({
            elem: '#demo'
            , height: 500
            , url: 'FindObjectManagerRolers/' //数据接口
            , cols: [[ //表头
                {field: 'role_id', title: '编号', width: 80, align: 'center', sort: true, fixed: 'left'}
                , {field: 'role_name', title: '角色'}
                , {field: 'r_explain', title: '说明'}
                , {field: 'title', title: '删除', align: 'center', templet: '#shanchu', event: 'shanchu'}
            ]]
        });

        table.on('tool(test)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            //删除
            if (layEvent === 'shanchu') { //删除
                layer.confirm('确定将删除  <#if objectManager.manager_name??>${objectManager.manager_name}</#if>的 ' + data.role_name + ' 角色吗？', function (index) {
                    //向服务端发送删除指令
                    $.ajax({
                        type: "post",
                        url: "shanchuRoleByRoleId",
                        data: {"role_id": data.role_id},
                        success: function (res) {
                            if (res.code == 1) {
                                layer.close(index);
                                layer.msg("删除成功！", {icon: 1});
                                // obj.del();
                                window.location.reload();
                            } else {
                                layer.msg("发生错误！", {icon: 5})
                            }
                        }
                    });
                    layer.close(index);
                });
            }
        });
    });
</script>

<script type="text/html" id="lahei">
    {{#  if(d.manager_status ==1){ }}
    <a href="javascript:;" class="layui-table-link">拉黑/恢复</a>
    {{#  } }}
</script>

<script type="text/html" id="status">
    {{#  if(d.manager_status ==1){ }}
    正常
    {{#  } }}
    {{#  if(d.manager_status ==-1){ }}
    <span style="color: red"> 黑名单</span>
    {{#  } }}
</script>

<script type="text/html" id="indexID">
    {{ d.LAY_INDEX }}
</script>
<script type="text/html" id="role">
    <a href="javascript:;" class="layui-table-link">查看角色</a>
</script>

<script type="text/html" id="shanchu">
    <a href="javascript:;" class="layui-table-link">删除</a>
</script>
<script type="text/html" id="weihu">
    <a href="findManagerInfo?manager_id={{d.manager_id}}" class="layui-table-link">维护</a>
</script>
</body>
</html>